package com.xiaoyu.lanling.feature.serverpush.event

import `in`.srain.cube.request.JsonData
import androidx.fragment.app.FragmentActivity
import com.xiaoyu.base.app.App
import com.xiaoyu.base.serverpush.event.ServerPushBaseEvent
import com.xiaoyu.base.utils.extensions.isDead
import com.xiaoyu.lanling.event.generosity.GenerosityLevelUpEvent
import com.xiaoyu.lanling.feature.generosity.GenerosityLevel
import com.xiaoyu.lanling.feature.generosity.GenerosityLogger
import com.xiaoyu.lanling.feature.generosity.dialog.GenerosityLevelUpDialog

class GenerosityLevelUpPush(jsonData: JsonData) : ServerPushBaseEvent(jsonData) {
    val data = GenerosityLevel(jsonData)
    override fun takeAction() {
        GenerosityLogger.logPushReceived()
        GenerosityLevelUpEvent(data).post()
        setComplete()
        val topActivity = (App.getInstance().topActivity as? FragmentActivity) ?: return
        if (topActivity.isDead()) {
            return
        }
        GenerosityLevelUpDialog.show(topActivity.supportFragmentManager, data)
    }
}